import Vue from 'vue'
import VueRouter, { RouteConfig, RawLocation } from 'vue-router'
import Layout from '../layout/index.vue'

Vue.use(VueRouter)

// 避免路由重复点击出错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location: RawLocation) {
  return (originalPush.call(this, location) as any).catch((err: any) => err)
}

// @ts-ignore
// @ts-ignore
export const constantRoutes: Array<RouteConfig> = [
  {
    path: '/login',
    component: () => import(/* webpackChunkName: "login" */ '../views/login/index.vue')
  },
  {
    path: '',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import(/* webpackChunkName: "sysIndex" */ '../views/sysIndex/index.vue'),
        name: '首页',
        meta: { title: '首页', icon: 'dashboard', noCache: true, affix: true }
      }
    ]
  },
  {
    path: '/404',
    component: () => import(/* webpackChunkName: "404" */ '../views/404/index.vue')
  },
  {
    path: '/401',
    component: () => import(/* webpackChunkName: "401" */ '../views/401/index.vue')
  },
  {
    path: '/system',
    component: Layout,
    children: [
      {
        path: 'user/profile',
        component: () => import(/* webpackChunkName: "profile" */ '../views/system/user/profile/index.vue'),
        name: 'Profile',
        meta: { title: '个人中心', icon: 'user' }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    children: [
      {
        path: 'dict/type/data/:dictId(\\d+)',
        component: () => import(/* webpackChunkName: "dict" */ '../views/system/dict/data.vue'),
        name: 'Data',
        meta: { title: '字典数据', icon: '' }
      }
    ]
  }
]

const router = new VueRouter({
  routes: constantRoutes
})

export default router
